// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  db.collection('user').where({
     _openid: event.open_id
  }).update({
    data: {
      user_name: event.user_name,
      code: event.code,
      role: event.role,
      academy: event.academy,
    },
    success: function(res) {
      console.log(res.data);
    },
    fail: function() {
      console.error("fail to update info");
    }
  })
}